package com.example.service.impl;


import com.example.mapper.NewsMapper;
import com.example.pojo.News;
import com.example.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class NewsServiceImpl implements NewsService {

    @Autowired
    private NewsMapper newsMapper;

    @Override
    public List<News> list() {
        return newsMapper.list();
    }

    @Override
    public void add(News news) {
        news.setPubTime(LocalDateTime.now());
//        if(news.getTypeName() == "类型一")news.setTypeId(1);
//        if(news.getTypeName() == "类型二")news.setTypeId(2);
        news.setTypeId(0);
        switch (news.getTypeName()){
            case "类型一":
                news.setTypeId(1);
                break;
            case "类型二":
                news.setTypeId(2);
                break;
            default:
                news.setTypeId(0);
                break;

        }
        newsMapper.add(news);
    }

    @Override
    public void deleteById(Integer newsId) {
        newsMapper.deleteById(newsId);
    }

    @Override
    public void uploadPic(String path) {
        newsMapper.uploadPic(path);
    }

    @Override
    public String[] picsList() {
        return newsMapper.picsList();
    }

    @Override
    public void deletePic() {
        newsMapper.deletePic();
    }
}
